package com.example.softwarearchitectureexamples.repository;

import com.example.softwarearchitectureexamples.dto.User;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

//基础持久层组件，包含增删查改,返回的是容器
@Repository
public interface UserRepository extends CrudRepository<User, Integer> {

    //基于地址id查用户信息
    @Query("select u.* from user u join address a on u.id = a.user_id where a.id=:aid")
    Optional<User> find(int aid);

    //基于账号密码查用户详细信息
    @Query("select u.* from user u where u.account=:account and u.password=:password")
    User find(String account, String password);
}

